package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "查询取消预约数量")
public class CancelReservationController {
    @Autowired
    private ReservationService reservationService;
    /**
     * 查询取消预约数量
     */
    @GetMapping(path = "/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> cancelReservationConut(){
        Integer count=reservationService.cancelReservationConut();
        return ResponseResult.success(count);
    }

    /**
     * 查询每个时间段剩余预约次数
     */
    @GetMapping(path = "/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<List<TimeCountVo>> countByTime(Long time){
        List<TimeCountVo> timeCount=reservationService.countByTime(time);
        return ResponseResult.success(timeCount);
    }

    /**
     *  新增预约
     */
    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult<Void> addReservation(@RequestBody ReservationDto reservationDto){
        reservationService.addReservation(reservationDto);
        return ResponseResult.success();
    }

    /**
     *  分页查询预约
     */
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public ResponseResult<PageResponse<ReservationVo>>  findByPage2(Integer pageNum,Integer pageSize,Integer status){
        PageResponse<ReservationVo> page=reservationService.findByPage2(pageNum,pageSize,status);
        return ResponseResult.success(page);
    }

    /**
     * 取消预约
     */
    @PutMapping(path = "/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult<Void> cancelReservation(@PathVariable Long id){
        reservationService.cancelReservation(id);
        return ResponseResult.success();
    }
}
